# -*- coding: utf-8 -*-
"""
Created on Tue Aug 28 13:39:24 2018

@author: Who

ASKVC财经
http://www.askvc.cn/

"""

from GetText import get_html_text
from cs import day
from WriteData import writedata
from Tk import genearteMD5
import re

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
}


def get_dates_xw(url, headers):
    text = get_html_text(url, headers)
    if not text:
        return None
    regex = re.compile(r'<li class="left">&nbsp;&nbsp;&nbsp;&nbsp;(\d{4}/\d{2}/\d{2}) \d{2}:\d{2}:\d{2}</li>')
    dates = re.findall(regex, text)
    return dates


def count_process_one():  # 资讯
    d1 = 0
    d2 = 0
    d3 = 0
    url = 'http://www.askvc.cn/'
    dates = get_dates_xw(url, headers)
    if not dates:
        return (d1, d2, d3)
    for date in dates:
        s = day(date.replace('/', '-'))
        if s == 0:
            d1 += 1
        elif s == 1:
            d2 += 1
        elif s == 2:
            d3 += 1

    return (d1, d2, d3)


def main():
    u = 'ASKVC财经'
    t1 = count_process_one()
    tk = genearteMD5(u)
    D = {tk: {"name": u, "today": t1[0], "yesterday": t1[1], "frontday": t1[2]}}
    writedata(D)

    return D


if __name__ == '__main__':
    print(main())
